package com.gitee.wsl.compose.ext

import androidx.compose.runtime.Stable
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.unit.Constraints

/**
 * Creates constraints with a fixed width and original height.
 */
@Stable
fun Constraints.fixedWidth(
    width: Int
): Constraints {
    require(width >= 0) {
        "width($width) must be >= 0"
    }
    return copy(minWidth = width, maxWidth = width)
}

/**
 * Creates constraints with a fixed height and original width.
 */
@Stable
fun Constraints.fixedHeight(
    height: Int
): Constraints {
    require(height >= 0) {
        "height($height) must be >= 0"
    }
    return copy(minHeight = height, maxHeight = height)
}

fun Constraints.maxSize() = Size(maxWidth.toFloat(), maxHeight.toFloat())

fun Constraints.minSize() = Size(minWidth.toFloat(), minHeight.toFloat())
